// pages/work/work.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    picPath: app.globalData.picPath,
    workList: [{
        img: '/img/workImg/work_shenpi.png',
        title: '审批中心'
      }, {
        img: '/img/workImg/work_richeng.png',
        title: '日程安排'
      },
      {
        img: '/img/workImg/work_huiyi.png',
        title: '工作报告'
      },
      {
        img: '/img/workImg/shareDoc.png',
        title: '共享文档'
      },
    ],
    notice: '',
    topImg: '',
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    indicatorColor: "#CFCCD0",
    indicatorActiveColor: '#2A6DDD'
  },


  toPage(e) {
    console.log(e);
    var nav = e.currentTarget.dataset.nav.title;
    if (nav == "审批中心") {
      wx.navigateTo({
        url: '/approval/pages/approval_center/approval_center',
      })
    } else if (nav == '日程安排') {
      wx.navigateTo({
        url: '/work/pages/riCheng/riCheng',
      })
    } else if (nav == '工作报告') {
      wx.navigateTo({
        url: '/work/pages/workReport_list/workReport_list',
      })
    } else if (nav == '员工报告') {
      wx.navigateTo({
        url: '/work/pages/check_report/check_report',
      })
    } else if (nav == '共享文档') {
      wx.navigateTo({
        url: '/work/pages/shareDoc/shareDoc',
      })
    }
  },
  toMsg() {
    wx.navigateTo({
      url: '/work/pages/message/message',
    })
  },
  toClock() {
    wx.navigateTo({
      url: '/work/pages/clockIn/clockIn',
    })
  },

  getData() {
    var url = app.globalData.url + "main/listMain",
      that = this,
      topImg = '',
      notice = '';
    wx.showLoading({
      title: '',
    })
    app.wxRequest(url, {
      memberId: app.globalData.memberId,
      flag: 1,
    }, res => {
      console.log(res);
      if (res.flag) {
        topImg = res.data.loopList;
        notice = res.data.noticeList[0].notice_title;
        that.setData({
          topImg,
          notice
        })
        console.log(notice);
        console.log(topImg);
        wx.hideLoading()
        wx.stopPullDownRefresh()
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData()
    var workList = this.data.workList;
    if (app.globalData.member.ifManager == 1 || app.globalData.member.inCharge == 1) {
      workList.push({
        img: '/img/workImg/checkImg.png',
        title: '员工报告'
      })
      this.setData({
        workList
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})